package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seawaterbt.ssm.config.DataSource;
import com.seawaterbt.ssm.config.DataSourceEnum;
import com.seawaterbt.ssm.entity.CzBasHeatsource;
import com.seawaterbt.ssm.entity.CzBasHeatsourceExit;
import com.seawaterbt.ssm.entity.ShengBasHeatsourceExit;
import com.seawaterbt.ssm.mapper.ShengBasHeatsourceExitMapper;
import com.seawaterbt.ssm.service.CzBasHeatsourceExitService;
import com.seawaterbt.ssm.service.ShengBasHeatsourceExitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class ShengBasHeatsourceExitServiceImpl extends ServiceImpl<ShengBasHeatsourceExitMapper, ShengBasHeatsourceExit> implements ShengBasHeatsourceExitService {

    @Autowired private CzBasHeatsourceExitService czBasHeatsourceExitService;
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean save(ShengBasHeatsourceExit entity) {
        return super.save(entity);
    }
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean saveOrUpdate(ShengBasHeatsourceExit entity) {
        return super.saveOrUpdate(entity);
    }

    @Override
    public void toSend() {
        QueryWrapper<CzBasHeatsourceExit> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("code",130981011).or().likeRight("code",130903007);
        List<CzBasHeatsourceExit> czlist = czBasHeatsourceExitService.list(queryWrapper);
        if (czlist != null){
            for (CzBasHeatsourceExit czBasHeatsourceExit:czlist){
                ShengBasHeatsourceExit shengBasHeatsourceExit = new ShengBasHeatsourceExit();
                shengBasHeatsourceExit.setADDTIME(czBasHeatsourceExit.getCreateTime());
                shengBasHeatsourceExit.setAREAPUBLIC(Double.parseDouble(czBasHeatsourceExit.getAreaPublic()==null?"0.0":czBasHeatsourceExit.getAreaPublic()));
                shengBasHeatsourceExit.setAREARESIDENT(Double.parseDouble(czBasHeatsourceExit.getAreaResident()==null?"0.0":czBasHeatsourceExit.getAreaResident()));
                shengBasHeatsourceExit.setAREARSELF(Double.parseDouble(czBasHeatsourceExit.getAreaRself()==null?"0.0":czBasHeatsourceExit.getAreaRself()));
                shengBasHeatsourceExit.setBAS_HEATSOURCEEXITADDRESS(czBasHeatsourceExit.getAddress());
                shengBasHeatsourceExit.setBAS_HEATSOURCEEXITID(czBasHeatsourceExit.getCodeProvince());
                shengBasHeatsourceExit.setBAS_HEATSOURCEEXITNAME(czBasHeatsourceExit.getHeatsourceExitName());
                shengBasHeatsourceExit.setHEATINGAREA(Double.parseDouble(czBasHeatsourceExit.getHeatingArea()==null?"0.0":czBasHeatsourceExit.getHeatingArea()));
                shengBasHeatsourceExit.setHEATSOURCEID(czBasHeatsourceExit.getCodeProvince().substring(0,12));
                shengBasHeatsourceExit.setREGIONAL("130");
                this.save(shengBasHeatsourceExit);
            }
        }
    }
}
